﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace DataAccess
{
    public class DBConnect
    {
        //public static SqlConnection GetConnection()
        //{
        //    string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        //    //string str = @"Data Source=.\;Initial Catalog=ATMSYSTEM;User ID=sa;Password=1234567";
        //    SqlConnection conn = new SqlConnection(str);
        //    if (conn.State == ConnectionState.Open)
        //    {
        //        conn.Close();
        //        conn.Dispose();
        //    }
        //    return conn;
        //}
        public static SqlConnection GetConnection()
        {
            string str = null;
            try
            {
                return new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            }
            catch
            {
                str = "Data Source=.;Initial Catalog=ATMSYSTEM;Persist Security Info=True;User ID=sa;Password=1234567";
            }
            SqlConnection cn = new SqlConnection(str);
            if (cn.State == ConnectionState.Open)
            {
                cn.Close();
                cn.Dispose();
            }
            return cn;
        }
    }
}
